<template>
  <div>
    <el-button type="primary" icon="el-icon-plus">添加</el-button>
    <el-table :data="tradeMarkList" border style="width: 100%; margin: 20px 0">
      <el-table-column type="index" label="序号" width="80" align="center">
      </el-table-column>
      <el-table-column prop="tmName" label="品牌名称"> </el-table-column>
      <el-table-column label="品牌LOGO">
        <template v-slot="scoped">
          <img :src="scoped.row.logoUrl" class="tradeMarkLogo" />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <el-button type="warning" icon="el-icon-edit" size="mini"
          >编辑</el-button
        >
        <el-button type="danger" icon="el-icon-delete" size="mini"
          >删除</el-button
        >
      </el-table-column>
    </el-table>
    <el-pagination
      style="text-align: center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[2, 3, 5, 10]"
      :page-size="limit"
      layout="prev, pager, next, jumper, -> , sizes, total"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { reqTradeMarkList } from "../../../api/product/trademark";

export default {
  name: "TradeMark",
  data() {
    return {
      page: 1, //当前页码
      limit: 3, //一个页面显示多少数量
      total: 0,
      tradeMarkList: [],
    };
  },
  methods: {
    handleSizeChange(value) {
      this.updateTradeMark(this.page, value);
    },
    handleCurrentChange(value) {
      this.updateTradeMark(value, this.limit);
    },
    async updateTradeMark(page, limit) {
      const { data } = await reqTradeMarkList(page, limit);
      const { current, pages, records, total } = data;
      this.page = current;
      this.limit = pages;
      this.total = total;
      this.tradeMarkList = records;
    },
  },
  mounted() {
    this.updateTradeMark(1, 3);
  },
};
</script>

<style scoped>
.tradeMarkLogo {
  width: 100px;
  height: 80px;
}
</style>
